<?php

namespace Trawind\Events\Subscribers\Inventory\Fulfillment;

use Trawind\Events\Events\Inventory\Fulfillment\DeleteMergePackEvent;
use Trawind\Events\Events\Inventory\Fulfillment\DeletePackEvent;
use Trawind\Events\Events\Inventory\Fulfillment\StoreMergePackEvent;
use Trawind\Events\Events\Inventory\Fulfillment\StorePackEvent;
use Trawind\Events\Events\Inventory\Fulfillment\SubmitMergePackEvent;
use Trawind\Events\Events\Inventory\Package\DeleteBoxEvent;
use Trawind\Events\Events\Inventory\Package\StoreBoxEvent;
use Trawind\Events\Events\Inventory\Receipt\DeletePutawayEvent;
use Trawind\Events\Events\Inventory\Receipt\StorePutawayEvent;
use Trawind\Events\Events\Inventory\Within\ProcessEvent;
use Trawind\Extension\Models\Deploy\BusinessType;

class PickSubscriber
{
    private $businessType = \Trawind\Basics\Enums\BusinessType::INVENTORY_FULFILLMENT_PICK;

    public function storePack($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, StorePackEvent::class);
        }
    }

    public function deletePack($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, DeletePackEvent::class);
        }
    }

    public function submitMergePack($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, SubmitMergePackEvent::class);
        }
    }

    public function deleteMergePack($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, DeleteMergePackEvent::class);
        }
    }

    public function storePutaway($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, StorePutawayEvent::class);
        }
    }

    public function deletePutaway($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, DeletePutawayEvent::class);
        }
    }

    public function storeMergePack($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, StoreMergePackEvent::class);
        }
    }

    public function storeBox($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, StoreBoxEvent::class);
        }
    }

    public function deleteBox($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, DeleteBoxEvent::class);
        }
    }

    public function process($event)
    {
        $repository = BusinessType::getEloquentById($this->businessType);
        $repository->callback($event->payload, ProcessEvent::class);
    }

    /**
     *
     * @param  \Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        $events->listen(
            StorePackEvent::class,
            static::class . '@storePack'
        );

        $events->listen(
            DeletePackEvent::class,
            static::class . '@deletePack'
        );

        $events->listen(
            SubmitMergePackEvent::class,
            static::class . '@submitMergePack'
        );

        $events->listen(
            DeleteMergePackEvent::class,
            static::class . '@deleteMergePack'
        );

        $events->listen(
            StorePutawayEvent::class,
            static::class . '@storePutaway'
        );

        $events->listen(
            DeletePutawayEvent::class,
            static::class . '@deletePutaway'
        );

        $events->listen(
            StoreMergePackEvent::class,
            static::class . '@storeMergePack'
        );

        $events->listen(
            StoreBoxEvent::class,
            static::class . '@storeBox'
        );

        $events->listen(
            DeleteBoxEvent::class,
            static::class . '@deleteBox'
        );

        $events->listen(
            ProcessEvent::class,
            static::class . '@process'
        );
    }
}
